package com.example.zy5.demos.web.test5;
import com.rabbitmq.client.*;
public class LogProducer {
    private final static String QUEUE_NAME = "logQueue";

    public static void main(String[] argv) throws Exception {
        // 创建连接和通道
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost"); // RabbitMQ 服务主机
        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {

            // 声明一个队列
            channel.queueDeclare(QUEUE_NAME, true, false, false, null);

            // 生产者发送日志消息
            String message = "This is a log message";
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println(" [x] Sent '" + message + "'");
        }
    }
}
